package org.shj.springcloud.zuul.filter;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;

/**
 * 可在配置文件中加入 zuul.PreReqLogFilter.pre.disable=true 即可禁用此过滤器
 * @author huangjian
 *
 */
public class PreReqLogFilter extends ZuulFilter{
	private static final Logger LOG = LoggerFactory.getLogger(PreReqLogFilter.class);

	@Override
	public Object run() {
		RequestContext ctx = RequestContext.getCurrentContext();
		HttpServletRequest request = ctx.getRequest();
		LOG.info(String.format("Send %s request to %s", request.getMethod(), request.getRequestURL()));
		return null;
	}

	@Override
	public boolean shouldFilter() {
		return true;
	}

	@Override
	public int filterOrder() { // 指定过滤器的执行顺序
		return 1;
	}

	@Override
	public String filterType() {
		return "pre"; //还有其它三种可能值：  route, post, error
	}
	

}
